 //根地址
 axios.defaults.baseURL = 'http://ajax-api.itheima.net'

 const topList = document.querySelector('.top');

 axios
   .get('/api/category/top')
   .then(({ data: res }) => {
     // console.log(res);

     const { data } = res
     const newArr = data.map((item) => {
       // console.log(item);
       return axios.get('/api/category/sub?id=' + item.id)
     })

     // console.log(newArr);
     return Promise.all(newArr)
   }).then((res) => {
     console.log(res);
     // res.data
     // const {data} = res
     // console.log(res);
     let html = res.map(({ data: item }) => {

       return `
       <li>
         <a href="javascript:;">${item.data.name}</a>
         <img
           src="${item.data.picture}"
           alt="" />
         <ul class="sub">
          ${item.data.children.map((item) => {
         return `
             <li>
             <a href="javascript:;">
               <span>${item.name}</span>
               <img src="${item.picture}"
                 alt="" />
             </a>
              </li>
             `
       }).join('')
         }
           </ul>
       </li>
         `
     }).join('')

     topList.innerHTML = html
   })


